/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */

void traversal(struct TreeNode*root,int* arr,int* i)
{
    if(root==NULL) return;
    arr[(*i)++]=root->val;
    traversal(root->left,arr,i);
   traversal(root->right,arr,i);
}

int trasize(struct TreeNode*root)
{
    if(root==NULL) return 0;
    return 1+trasize(root->left)+trasize(root->right);
}

int* preorderTraversal(struct TreeNode* root, int* returnSize) 
{
   *returnSize=trasize(root);
   int *arr=(int*)malloc(sizeof(int)*(*returnSize));
   int i=0;
   traversal(root,arr,&i);
    return arr;
}
